package com.bjpowernode.config.context;


import com.bjpowernode.service.DicTypeService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 获取spring容器Bean的封装工具类
 */
@Component
public class ApplicationContextProvider implements ApplicationContextAware {

    //类变量
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ApplicationContextProvider.applicationContext = applicationContext;
    }

    public static <T> T getBean(Class<T> beanClazz) {
        return ApplicationContextProvider.applicationContext.getBean(beanClazz);
    }
}
